const KEY = 'my-token'
// const value = 'admin-token'

export function setToken(value){
  window.localStorage.setItem(KEY,value)
}

export function getToken(){
  var tokenStr = window.localStorage.getItem(KEY)
  if(!tokenStr || tokenStr=='undefined'){
    return null
  }else{
    return tokenStr
  }
}

export function removeToken(){
  window.localStorage.removeItem(KEY)
}

const userKey = 'user-info-2020'

export function saveUserInfo(userInfo){
  if(userInfo){//userInfo是一个对象，存入本地存储之前，要变成字符串
    var userInfoStr = JSON.stringify(userInfo)
    window.localStorage.setItem(userKey,userInfoStr)
  }
}

export function getUserInfo(){
 var userInfoStr = window.localStorage.getItem(userKey)
 if(!userInfoStr || userInfoStr==='undefined'){
   return null
 }else{
   var userInfo = JSON.parse(userInfoStr)
   return userInfo
 }
}

export function removeUserInfo(){
  window.localStorage.removeItem(userKey)
}

export function clearUser(){
  removeToken()
  removeUserInfo()
}